<template>
  <div class="login">
    <div class="left-box"></div>

    <div class="right-box">
      <div class="logo-box">
        <img src="../assets/st.png" alt="carpark" class="right-box-img" />
      </div>

      <div class="mms-box">
        <img src="../assets/mms.png" alt="carpark" class="right-box-img" />
      </div>

      <p class="login-tips-1">Login to Your Accout</p>
      <p class="login-tips-2">Welcome to the PSD MMS, sign in to continue</p>

      <div class="account-box">
        <el-input v-model="inputAccount" placeholder="E-mail" />

        <el-input
          v-model="inputPsw"
          type="password"
          placeholder="Password"
          :show-password="showPassword"
        />

        <div class="forgot">
          <div><input type="checkbox" /> Remember me</div>
          <div style="color: #3bcdbd">Forgot Password?</div>
        </div>

        <div>
          <el-button @click="loginHandle()">LOGIN</el-button>
          <el-button @click="loginHandle()" class="signup">SIGNUP</el-button>
        </div>
      </div>

      <!-- <div class="select-language">
        <el-select v-model="Selectvalue" class="m-2" placeholder="Select">
          <el-option value="English" />
          <el-option value="Chinese" />
        </el-select>
      </div> -->
    </div>
  </div>
</template>

<script>
// @ is an alias to /src
// import HelloWorld from "@/components/HelloWorld.vue";
import { getCurrentInstance, onMounted, reactive, toRefs } from "vue";
import { useRouter } from "vue-router";

export default {
  name: "login",
  components: {
    // HelloWorld,
  },

  setup() {
    let router = useRouter();

    let state = reactive({
      showPassword: true,
      inputAccount: "maintenanceManager",
      inputPsw: "123456",
      Selectvalue: "Chinese",
      cityCode:"",
      lineCode:""
    });

    function loginHandle() {
      rq.post("/auth/login", {
        username: state.inputAccount,
        password: state.inputPsw,
      }).then((res) => {
        // console.log(res, "token");

        localStorage.setItem("token", `Bearer ${res.data.data.accessToken}`);
        // 获取登陆的用户信息
        rq.get("system/user/getInfo").then((res) => {
          // console.log( res.data.data.user.location.cityCode,"个人信息");
            // console.log( res.data.data.user.location.lineCode,"个人信息");
          localStorage.setItem(
            "lastLoginDate",
            res.data.data.user.lastLoginDate
          );

          localStorage.setItem("roleKey", res.data.data.user.roles[0].roleKey);

           localStorage.setItem("cityCode", res.data.data.user.location.cityCode);
                  localStorage.setItem("lineCode",res.data.data.user.location.lineCode);
        });
        router.push({
          //传递参数使用query的话，指定path或者name都行，但使用params的话，只能使用name指定
          path: "/index/home",
          // query: {
          //   num: 1,
          // },
        });
      });
    }

    // 获取全局挂载的参数,main.jsY原型挂载
    const { proxy } = getCurrentInstance();
    const rq = proxy.$instance;

    onMounted(() => {});

    return {
      loginHandle,
      rq,
      ...toRefs(state),
    };
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
.login {
  box-sizing: border-box;
  display: flex;

  .left-box {
    width: 60vw;
    height: 100vh;
    background-image: url("../assets/indexleft.png");
    background-size: 100% 100%;
    background-repeat: no-repeat;
  }
  .right-box {
    width: 40vw;
    height: 100vh;

    box-sizing: border-box;

    .logo-box {
      text-align: end;
    }
    .right-box-img {
      height: 100px;
    }
    .mms-box {
      text-align: center;
      margin: 5vh auto;
    }
    .login-tips-1 {
      text-align: center;
      font-size: 60px;
      font-weight: 800;
      margin: 10px 0;
    }
    .login-tips-2 {
      text-align: center;
      font-size: 28px;
      margin: 10px 0;
    }
    .account-box {
      text-align: center;
    }
    .el-input {
      width: 80%;
      margin-top: 30px;
      height: 40px;
    }
    .forgot {
      display: flex;
      justify-content: space-evenly;
      margin: 16px AUTO;
      font-size: 24px;
    }
    .el-button {
      width: 40%;
      margin-top: 16px;
      background-color: #00bdb5;
      color: white;
      font-weight: 500;
      height: 40px;
    }
    .signup {
      background: #fff;
      border: 1px solid #00bdb5;
      color: #00bdb5;
    }
    .select-language {
      text-align: center;
      margin-top: 32px;
    }
  }
}
</style>
